REM	*******************************************************************************
REM	
REM	 build.bat - Run a complete build which converts the latex source to pdf, odt and html.
REM	
REM	 Copyright (c) 2009 Philip Wenig
REM	
REM	 This library is free software; you can redistribute it and/or
REM	 modify it under the terms of the GNU Lesser General Public
REM	 License as published by the Free Software Foundation; either
REM	 version 2.1 of the License, or (at your option) any later version.
REM	
REM	 This library is distributed in the hope that it will be useful,
REM	 but WITHOUT ANY WARRANTY; without even the implied warranty of
REM	 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
REM	 Lesser General Public License for more details.
REM	
REM	 You should have received a copy of the GNU Lesser General Public
REM	 License along with this library; if not, write to the Free Software
REM	 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
REM	 
REM	 Contributors:
REM		Philip Wenig
REM	
REM	*******************************************************************************/

REM	
REM	 Remove the old build.log file.
REM	
echo '---------------' >> build.log
del -f build.log
echo 'remove old build.log ... done' >> build.log
echo '---------------' >> build.log

REM	
REM	 Converts all eps files in figures to pdf with epstopdf.
REM	
echo 'run eps conversion to pdf ...' >> build.log
cd ..
cd include
for /R %%f in (*.eps) do (
	echo 'convert file %%f' >> ./../content/build.log
	C:\Programme\MiKTeX-2.7\miktex\bin\epstopdf "%%f"
	echo 'done' >> ./../content/build.log	
)
cd ..
cd content
echo '---------------' >> build.log

REM	
REM	 Run the initial latex compilation.
REM	
echo 'run first compilation ...' >> build.log
C:\Programme\MiKTeX-2.7\miktex\bin\latex -interaction=nonstopmode main.tex
echo 'done' >> build.log

REM	
REM	 Compile the document 3 times to include abbreviations, index and bibliography correctly.
REM	
echo 'compile abbreviations, index, bibliography 3x ...' >> build.log
for %%i in (1,2,3) do (
	REM	 abbreviations
	echo 'run abbreviations' >> build.log		
	C:\Programme\MiKTeX-2.7\miktex\bin\makeindex main.nlo -s nomencl.ist -o main.nls
	echo 'abbreviations done run: %%i' >> build.log
	REM	 index
	echo 'run index' >> build.log	
	C:\Programme\MiKTeX-2.7\miktex\bin\makeindex main.idx -o main.ind
	echo 'index done run: %%i' >> build.log	
	REM	 bibliography
	echo 'run bibliography' >> build.log	
	C:\Programme\MiKTeX-2.7\miktex\bin\bibtex main.aux
	echo 'bibliography done run: %%i' >> build.log
)
echo '---------------' >> build.log

REM	
REM	 Create the dvi file.
REM	
echo 'run second compilation ...' >> build.log	
C:\Programme\MiKTeX-2.7\miktex\bin\latex -interaction=nonstopmode main.tex
echo 'done' >> build.log
echo '---------------' >> build.log

REM	
REM	 Converts eps to pdf and creates the pdf file.
REM	
echo 'run pdf compilation ...' >> build.log
REM	 TODO MikTeX has another command, not shell-escape.
C:\Programme\MiKTeX-2.7\miktex\bin\pdflatex -shell-escape -interaction=nonstopmode main.tex
echo 'done' >> build.log
echo '---------------' >> build.log

REM	
REM	 Converts the document to a odf file.
REM	 Could be also htlatex 'main.tex' 'xhtml,ooffice' 'ooffice/! -cmozhtf' '-coo' '-cvalidate'
REM	 
echo 'run odt compilation ...' >> build.log	
REM htlatex main.tex 'xhtml,ooffice' 'ooffice/! -cmozhtf' '-coo' '-cvalidate'
C:\Programme\MiKTeX-2.7\miktex\bin\oolatex.exe main.tex
echo 'TODO odt conversion is still not working'
echo 'done' >> build.log
echo '---------------' >> build.log

REM	
REM	 Converts the latex document to html.
REM	
echo 'run html compilation ...' >> build.log	
REM htlatex 'main.tex' 'html,info'
htlatex main.tex
echo 'done' >> build.log
echo '---------------' >> build.log

REM	
REM	 Everythings has been compiled correctly.
REM	
echo 'Congratulations, no problems have been occured' >> build.log
